package app.msy.cn.takephoto.camera;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.view.View;

import java.util.List;

public class RealTimeDetectedBorderView extends View {
    private List<Point> mPoints;

    public RealTimeDetectedBorderView(Context paramContext) {
        super(paramContext);
    }

    protected void onDraw(Canvas paramCanvas) {
        if ((this.mPoints == null) || (this.mPoints.size() != 4))
            return;
        Paint localPaint = new Paint();
        localPaint.setColor(Color.BLUE);
        localPaint.setStyle(Paint.Style.FILL);
        localPaint.setAntiAlias(true);
        paramCanvas.drawRect(0.0F, 0.0F, getWidth(), getHeight(), localPaint);
        localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        localPaint.setColor(Color.BLUE);
        Path localPath = new Path();
        localPath.moveTo(((Point) this.mPoints.get(0)).x, ((Point) this.mPoints.get(0)).y);
        localPath.lineTo(((Point) this.mPoints.get(1)).x, ((Point) this.mPoints.get(1)).y);
        localPath.lineTo(((Point) this.mPoints.get(2)).x, ((Point) this.mPoints.get(2)).y);
        localPath.lineTo(((Point) this.mPoints.get(3)).x, ((Point) this.mPoints.get(3)).y);
        localPath.close();
        paramCanvas.drawPath(localPath, localPaint);
        localPaint.setStyle(Paint.Style.STROKE);
        localPaint.setStrokeWidth(5.0F);
        localPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
        int i = 0;
        while (i < this.mPoints.size()) {
            paramCanvas.drawLine(((Point) this.mPoints.get(i)).x, ((Point) this.mPoints.get(i)).y, ((Point) this.mPoints.get((i + 1) % this.mPoints.size())).x, ((Point) this.mPoints.get((i + 1) % this.mPoints.size())).y, localPaint);
            i += 1;
        }
        super.onDraw(paramCanvas);
    }

    public void setPoints(List<Point> paramList) {
        this.mPoints = paramList;
    }
}